#ifndef THINK_THINK_SESSION_DRIVER_REDIS_H
#define THINK_THINK_SESSION_DRIVER_REDIS_H

static char* think_session_driver_redis =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think\\session\\driver;\n"
	"\n"
	"use SessionHandler;\n"
	"use think\\Exception;\n"
	"\n"
	"class Redis extends SessionHandler\n"
	"{\n"
	"    /** @var \\Redis */\n"
	"    protected $handler = null;\n"
	"    protected $config  = [\n"
	"        \'host\'         => \'127.0.0.1\', // redis主机\n"
	"        \'port\'         => 6379, // redis端口\n"
	"        \'password\'     => \'\', // 密码\n"
	"        \'select\'       => 0, // 操作库\n"
	"        \'expire\'       => 3600, // 有效期(秒)\n"
	"        \'timeout\'      => 0, // 超时时间(秒)\n"
	"        \'persistent\'   => true, // 是否长连接\n"
	"        \'session_name\' => \'\', // sessionkey前缀\n"
	"    ];\n"
	"\n"
	"    public function __construct($config = [])\n"
	"    {\n"
	"        $this->config = array_merge($this->config, $config);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 打开Session\n"
	"     * @access public\n"
	"     * @param string $savePath\n"
	"     * @param mixed  $sessName\n"
	"     * @return bool\n"
	"     * @throws Exception\n"
	"     */\n"
	"    public function open($savePath, $sessName)\n"
	"    {\n"
	"        // 检测php环境\n"
	"        if (!extension_loaded(\'redis\')) {\n"
	"            throw new Exception(\'not support:redis\');\n"
	"        }\n"
	"        $this->handler = new \\Redis;\n"
	"\n"
	"        // 建立连接\n"
	"        $func = $this->config[\'persistent\'] ? \'pconnect\' : \'connect\';\n"
	"        $this->handler->$func($this->config[\'host\'], $this->config[\'port\'], $this->config[\'timeout\']);\n"
	"\n"
	"        if (\'\' != $this->config[\'password\']) {\n"
	"            $this->handler->auth($this->config[\'password\']);\n"
	"        }\n"
	"\n"
	"        if (0 != $this->config[\'select\']) {\n"
	"            $this->handler->select($this->config[\'select\']);\n"
	"        }\n"
	"\n"
	"        return true;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 关闭Session\n"
	"     * @access public\n"
	"     */\n"
	"    public function close()\n"
	"    {\n"
	"        $this->gc(ini_get(\'session.gc_maxlifetime\'));\n"
	"        $this->handler->close();\n"
	"        $this->handler = null;\n"
	"        return true;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 读取Session\n"
	"     * @access public\n"
	"     * @param string $sessID\n"
	"     * @return string\n"
	"     */\n"
	"    public function read($sessID)\n"
	"    {\n"
	"        return (string) $this->handler->get($this->config[\'session_name\'] . $sessID);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 写入Session\n"
	"     * @access public\n"
	"     * @param string $sessID\n"
	"     * @param String $sessData\n"
	"     * @return bool\n"
	"     */\n"
	"    public function write($sessID, $sessData)\n"
	"    {\n"
	"        if ($this->config[\'expire\'] > 0) {\n"
	"            return $this->handler->setex($this->config[\'session_name\'] . $sessID, $this->config[\'expire\'], $sessData);\n"
	"        } else {\n"
	"            return $this->handler->set($this->config[\'session_name\'] . $sessID, $sessData);\n"
	"        }\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 删除Session\n"
	"     * @access public\n"
	"     * @param string $sessID\n"
	"     * @return bool\n"
	"     */\n"
	"    public function destroy($sessID)\n"
	"    {\n"
	"        return $this->handler->delete($this->config[\'session_name\'] . $sessID) > 0;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * Session 垃圾回收\n"
	"     * @access public\n"
	"     * @param string $sessMaxLifeTime\n"
	"     * @return bool\n"
	"     */\n"
	"    public function gc($sessMaxLifeTime)\n"
	"    {\n"
	"        return true;\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif